<template>
  <el-select v-model="currentValue" @change="selectChange" v-bind="$attrs" size="small" style="width: 100%" clearable>
    <el-option v-for="(item, index) in optinons" :key="index" :value="item.DictId" :label="item.DictName"></el-option>
  </el-select>
</template>

<script>
// import {dictApi} from '@/api/organizationApiNow.js'
import dictApi from '@/api/organizationApi/dictApi.js'

export default {
  name: "SelectDeparament",
  props: {
    // v-model绑定的数据
    value: {
      type: [String, Number],
      default: function () {
        return null
      }
    },
    DictTypeCode: {
      type: [String],
      default: function () {
        return ''
      }
    },
    exclude: {
      type: Array,
      default: function () {
        return []
      }
    }
  },
  computed: {
    // 转换绑定的选中数据，与v-model同步
    currentValue: {
      get: function () {
        return this.value
      },
      set: function (value) {
        this.$emit('input', value)
      }
    },
    api() {
      return authcenterApi.role
    }
  },
  mounted() {
    this.getList()
  },
  data() {
    return {
      optinons: []
    }
  },
  methods: {
    selectChange (a) {
      let DictId = a
      let b = this.optinons.filter(it => {
        return it.DictId === DictId
      })
      this.$emit('selectChange', DictId, b)
    },
    getList() {
      if (this.DictTypeCode && this.DictTypeCode !== '') {
        this.$store.dispatch('GetDictItems', this.DictTypeCode).then(res => {
          res.sort((a, b) => a.sortNo - b.sortNo)
          let w = res.filter(it => !this.exclude.some((it1) => it1.DictId === it.DictId))
          this.optinons = w
        })
      }
      // dictApi.getList().then(res => {
      //   this.optinons = res.filter(item => {
      //     return item.DictTypeCode === this.DictTypeCode
      //   })
      // })
    }
  }
}
</script>

<style scoped>

</style>
